package com.xiumu.controller.blog;

import com.xiumu.common.core.result.ResultJSON;
import com.xiumu.pojo.blog.query.BlogTagQuery;
import com.xiumu.service.blog.BlogTagService;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文章标签 Controller
 *
 * @author XiuMu
 * @Date 2023-01-30 14:22:50
 */
@RestController
public class BlogTagController {

    @Autowired
    private BlogTagService blogTagService;

    /**
     * 查询标签
     *
     * @param query 查询条件
     * @return
     */
    @GetMapping("/blogTag")
    public ResultJSON<List<String>> list(BlogTagQuery query) {
        return ResultJSON.querySuccess(blogTagService.listByBlogTagQuery(query));
    }

    /**
     * 创建 blogTag
     *
     * @param tagName 标签名称
     * @return
     */
    @PostMapping("/blogTag/{tagName}")
    public ResultJSON<Boolean> create(@NotBlank(message = "标签名称不能为空") @PathVariable("tagName") String tagName) {
        return ResultJSON.createSuccess(blogTagService.create(tagName));
    }
}
